﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SweeperPrototype.Business.Fields;

namespace SweeperPrototype.Objects
{
	public partial class EffectiveExposure
	{
        public class EffectiveExposureUpdate
        {
            private readonly Timestamp m_Timestamp;
            private readonly Shares m_Quantity;
            private readonly Multiplier m_Multiplier;

            public EffectiveExposureUpdate( EffectiveExposure exposure, PositionSubscription.PositionUpdate pos_update)
                : this(exposure, null, pos_update )
            {}

            public EffectiveExposureUpdate( EffectiveExposure exposure, ExposureMappingSubscription.ExposureMappingUpdate ex_map_update)
                : this( exposure, ex_map_update, null )
            {}

            public EffectiveExposureUpdate( EffectiveExposure exposure, 
                ExposureMappingSubscription.ExposureMappingUpdate ex_map_update,
                PositionSubscription.PositionUpdate position_update
                )
            {
                m_Timestamp = null;
                if (ex_map_update == null )
                {
                    m_Multiplier = exposure.Multiplier;
                }
                else
                {
                    m_Timestamp = ex_map_update.Timestamp;
                    m_Multiplier = ex_map_update.Multiplier;
                }
                if (position_update == null)
                {
                    m_Quantity = exposure.Quantity;
                }
                else
                {
                    if (m_Timestamp == null 
                        || position_update.Timestamp.Value > m_Timestamp.Value)
                    {
                        m_Timestamp = position_update.Timestamp;
                    }
                    m_Quantity = position_update.Quantity;
                }
            }

            public Timestamp Timestamp
            {
                get { return m_Timestamp; }
            }

            public Shares Quantity
            {
                get { return m_Quantity; }
            }

            public Multiplier Multiplier
            {
                get { return m_Multiplier; }
            }
        }
	}
}
